package game

import (
	"math/rand"

	. "gddgame.cc/galaxy/common/dsl/game"
	. "gddgame.cc/galaxy/common/dsl/game/achievement"
	. "gddgame.cc/galaxy/common/dsl/game/base"
	. "gddgame.cc/galaxy/common/dsl/game/group"
	. "gddgame.cc/galaxy/common/dsl/game/stat"
	. "gddgame.cc/galaxy/common/dsl/game/user"
	"gddgame.cc/galaxy/core/models"
	"gddgame.cc/galaxy/project/maze/maze/model"
	"gddgame.cc/galaxy/project/maze/maze/model/player_model"
	"gddgame.cc/galaxy/project/maze/maze/model/player_single"
	"gddgame.cc/galaxy/utils/uuid"
)

type Language struct {
}

type Center struct {
	env *Environment

	*GroupData

	*StatData

	*BaseData

	*AchievementData

	*UserData

	*player_model.PlayerModelData
	*player_single.PlayerSingleData

	// 分语言统计
	Languages map[string]*Language
}

func NewCenter(env *Environment) *Center {
	return &Center{
		env:       env,
		Languages: make(map[string]*Language, len(env.LanguageList)),
	}
}

func (center *Center) Compute() {
	center.initLanguage()
}

func (center *Center) initLanguage() {
	for _, language := range center.env.LanguageList {
		L := &Language{}
		center.Languages[language] = L
	}
}

func (center *Center) GetUserFromOpen(open *models.UserOpen) UserBase {
	var u model.User
	if open.Id == "" {
		openId := uuid.RandomString()
		u = model.User{OpenId: openId, BaseId: 0, Entity: center.PlayerModelData.Random().Key, OnlineScore: int(rand.Int31n(10))}
		open.Avatar = u.Entity
	} else {
		_ = center.FindUser(open.Id, &u)
	}
	return &u
}
